package com.xpgk.mvc.messageModel;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.scallVisit.ScallVisit;
import com.xpgk.mvc.scallVisit.ScallVisitService;

public class MessageModelController extends  BaseController {

	
	public static final String messageModel_splitPageSelect = "sys.messageModel.splitPageSelect";
	
	public static final String messageModel_splitPageFrom = "sys.messageModel.splitPageFrom";
	
	private MessageModelService messageModelService = new MessageModelService();

	
	//private ScallVisitService scallVisitService = new ScallVisitService();
	
	public void index(){
		render("messageModel.html");
	}
	
	/*
	 * 短信模板查询
	 */
	public void queryModel(){
		String json = paging(splitPage, messageModel_splitPageSelect, messageModel_splitPageFrom);
		renderJson(json);
	}
	/*
	 * 新增短信模板
	 */
	public void addModel(){
		render("messageModelAdd.html");
	}
	/*
	 * 删除短信模板
	 */
	public void delectMessageModel(){
		List<ShortMessage> poList = getModels(ShortMessage.class);
		for(ShortMessage cus : poList){
			System.out.println(cus.getStr("ids"));
			boolean result = cus.delete();
			System.out.println(result);
			
		}
		render("messageModelAdd.html");
	}
	/*
	 * 保存新增短信模板
	 */
	@Before(Tx.class)
	public void saveMessageModelAdd(){
		ShortMessage shortMessage = getModel(ShortMessage.class);
		shortMessage.set("status","禁用");
		RenderBean result = messageModelService.saveMessageModelAdd(shortMessage);
		renderJson(result);
	}
	/*
	 * 修改短信模板状态（禁用）
	 */
	@Before(Tx.class)
	public void updataMessageModel(){
		String ids = getPara("ids");
		ShortMessage shortMessage = ShortMessage.dao.findById(ids);
		shortMessage.set(ShortMessage.column_status,"禁用");
		boolean result = shortMessage.update();
		System.out.println(result);
		renderJson(result);
	}
	
	/*
	 * 修改短信模板状态（启用）
	 */
	@Before(Tx.class)
	public void updataMessageModelStart(){
		String ids = getPara("ids");
		ShortMessage shortMessage = ShortMessage.dao.findById(ids);
		shortMessage.set(ShortMessage.column_status,"启用");
		boolean result = shortMessage.update();
		System.out.println(result);
		renderJson(result);
	}
}
